#include "StdAfx.h"
#include "CurveCtrl.h"

#define DEF_YRANGE 200
#define DEF_CROPVAL	200

int CCurveCtrl::m_nDisRange = DEF_YRANGE;
CCurveCtrl::CCurveCtrl(void)
{
	AtBeginClass();
}

CCurveCtrl::~CCurveCtrl(void)
{
	AtEndClass();
}

int CCurveCtrl::AtBeginClass(void)
{
	m_nDisRange = DEF_YRANGE;
	return 0;
}

int CCurveCtrl::AtEndClass(void)
{
	return 0;
}

void CCurveCtrl::DoDrawing(CDC *pDC, COLORREF lColor, int nPenWidth)
{
	int nSize = m_vecPoint.size();
	float fSize = m_vecPoint.size() -1;
	float fWidth = m_RectRange.Width();
	float fMove = fWidth/fSize;

	GraphicsPath bezierPath;
	Graphics graphics(pDC->m_hDC);
	Pen pen(Color( 255, GetRValue(lColor), GetGValue(lColor), GetBValue(lColor)), 1.0f);

	graphics.SetSmoothingMode( SmoothingModeAntiAlias );
	graphics.SetInterpolationMode( InterpolationModeHighQualityBicubic );
	for( int i=0; i<nSize -1; i++ )
	{
		int nPosYPrev = m_vecPoint[i];
		int nPosYNext = m_vecPoint[i+1];
/*	
		bezierPath.AddLine( m_RectRange.left + int(fMove*i), m_RectRange.top + (m_RectRange.Height()*nPosYPrev)/DEF_YRANGE,	\
			m_RectRange.left + int(fMove*(i+1)), m_RectRange.top + (m_RectRange.Height()*nPosYNext)/DEF_YRANGE );
			/**/
		graphics.DrawLine(&pen,m_RectRange.left + int(fMove*i), m_RectRange.top + (m_RectRange.Height()*nPosYPrev)/DEF_YRANGE,	\
			m_RectRange.left + int(fMove*(i+1)), m_RectRange.top + (m_RectRange.Height()*nPosYNext)/DEF_YRANGE );
	}
//	graphics.DrawPath(&pen, &bezierPath);

}

int CCurveCtrl::SetPosData(void)
{
	int nSize = m_vecPoint.size();

	for( int i=0; i<nSize; i++ )
	{
		int nPosYPrev = m_vecPoint[i];

		int nPosX = (m_RectRange.Width()*i)/nSize;
		int nPosY = (m_RectRange.Height()*nPosYPrev)/DEF_YRANGE;
		POINT point;
		point.x = nPosX;
		point.y = nPosY;

		m_vecPointPos.push_back( point );
	}
	return 0;
}
